package com.lbd99.data.lbd.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lbd99.data.lbd.service.TBankCardService;
import com.lbd99.data.lbd.service.TUserService;
import com.lbd99.data.lbd.vo.SysAccount;
import com.lbd99.data.lbd.vo.TUser;

@Controller
@RequestMapping("tBankCard")
public class TBankCardController {

	@Autowired
	private TBankCardService tBankCardService;
	@Autowired
	private TUserService tUserService;
	
	@RequestMapping(value = "/getTBankCardList")
	@ResponseBody
	public Map<String, Object> getTBankCardList(String name,int page,int rows,HttpSession httpSession){
		SysAccount sysAccount = (SysAccount)httpSession.getAttribute("SESSION_INFO_OBJECT");//获取当前登录的用户
    	Map<String, Object> result = new HashMap<String, Object>();
    	Map<String,Object> map=new HashMap<String,Object>();
        if(sysAccount.getType()==1){//如果是普通管理员，用手机号查询出user信息
        	TUser user = tUserService.selectByPhone(sysAccount.getTel());
        	if(user!=null){
        		map.put("rootUserId",user.getId()+"");
        	}
        }
		map.put("name", StringUtils.trim(name));
		PageHelper.startPage(page, rows);
		List<Map<String,Object>> list = tBankCardService.selectListMap(map);
		PageInfo<Map<String,Object>> pages = new PageInfo<Map<String,Object>>(list);
		result.put("total", pages.getTotal());
		result.put("rows", pages.getList());
		return result;
	}
	
}
